
import { clearFeatureByName, drawFeatureFromWKT, findFeatureByName } from "@/utils/map/earthDrawHandler.js";

let featureHightTag = 'identifyFeatureGeoHightlight'

export function clearHightFeature() {
  clearFeatureByName(featureHightTag)
}

export function highlightFeature(wkt) {
  clearHightFeature()
  const fillColor = Cesium.Color.fromCssColorString('#FFD700')
  fillColor.alpha = 0.4
  drawFeatureFromWKT(featureHightTag, wkt, {
    color: Cesium.Color.fromCssColorString('#FFD700'),
    outline: true,
    width: 3,
    outlineColor: Cesium.Color.fromCssColorString('#FFD700'),
    outlineWidth: 3,
    fill: true,
    material: fillColor, //new Cesium.ColorMaterialProperty(fillColor),
    clampToGround: Cesium.HeightReference.CLAMP_TO_GROUND,
    extrudedHeight: 20,
    speed: 1
  })
}

export function highLightWkt(wkt, name, zoomTo = true, fill = true) {
  drawFeatureFromWKT(name, wkt, {
    availability: new Cesium.TimeIntervalCollection([
      new Cesium.TimeInterval({
        start: viewer.clock.currentTime,
        stop: Cesium.JulianDate.addSeconds(
          viewer.clock.currentTime,
          8,
          new Cesium.JulianDate()
        )
      })
    ]),
    fill: fill,
    material: new Cesium.ColorMaterialProperty(new Cesium.CallbackProperty(function color(time, result) {
      let txf = Math.floor(time.secondsOfDay);
      if (txf % 2 === 0) {//间隔两秒变换
        result = Cesium.Color.FLORALWHITE.withAlpha(0.9);
      } else {
        result = Cesium.Color.FLORALWHITE.withAlpha(0);
      }
      return result;
    }, false))
  })
  return findFeatureByName(name)
}